package com.csweimei.rentmanagementtreasure.utils;

import android.util.Log;

import java.util.Map;
import java.util.Random;

public class PayUtil {
    /**
     * 获得app签名
     * @param map
     * @return
     */
    public static String genAppSign(Map<String, String> map, String wxApiKey) {
        StringBuilder sb = new StringBuilder();

        for (Map.Entry<String, String> entry :map.entrySet()){
            sb.append(entry.getKey())
                    .append('=')
                    .append(entry.getValue())
                    .append('&');
        }
        sb.append("key=").append(wxApiKey);
        String str = sb.toString();
        Log.e("TAG",str);
        String appSign = MD5.getMessageDigest(str.getBytes());
        return appSign == null ? null : appSign.toUpperCase();
    }

    /**得到随机字符串*/
    public static String genNonceStr() {
        Random random = new Random();
        return MD5.getMessageDigest(String.valueOf(random.nextInt(10000)).getBytes());
    }
}
